#!/usr/bin/env python
# encoding: utf-8
'''
Adb.MachModel -- shortdesc

Adb.MachModel is a description

It defines classes_and_methods

@author:     Anson Chan

@copyright:  2016 Xerland Co. Ltd. All rights reserved.

@contact:    anson_chan@xerland.com
@deffield    updated: Updated
'''
from Utils.SysConstants import TPLUS_MACH_POWER_STATE_OFF,\
    TPLUS_MACH_POWER_STATE_ON, TPLUS_MACH_POWER_STATE_NONE,\
    TPLUS_ABNORMAL_DATETIME

class MachModel(object):
    '''
    classdocs
    '''


    def __init__(self, mMachID=None, mMachName=None, mPowerOnTime=None, mPowerOffTime=None):
        '''
        Constructor
        '''
        self.mMachID = mMachID
        self.mMachName = mMachName
        self.mPowerOnTime = mPowerOnTime
        self.mPowerOffTime = mPowerOffTime
        
    def __eq__(self,other):
        if not other:
            return False
        return (
                self.mMachID == other.mMachID 
                and self.mMachName == other.mMachName 
                and self.mPowerOnTime == other.mPowerOnTime
                and self.mPowerOffTime == other.mPowerOffTime
                )
        
    def getMachId(self):
        return self.mMachID
    
    def getMachName(self):
        return self.mMachName
    
    def getPowerState(self):
#        if (not self.mPowerOffTime and self.mPowerOffTime != "None" and self.mPowerOnTime) or self.mPowerOffTime == TPLUS_ABNORMAL_DATETIME:
#            return TPLUS_MACH_POWER_STATE_NONE
#        if self.mPowerOffTime:
#            return TPLUS_MACH_POWER_STATE_OFF
#        else:
#            return TPLUS_MACH_POWER_STATE_ON
#        
        if self.mPowerOnTime and self.mPowerOnTime != "None":
            if not self.mPowerOffTime or self.mPowerOffTime == "None":
                return TPLUS_MACH_POWER_STATE_ON
            if self.mPowerOffTime and self.mPowerOffTime != "None" and self.mPowerOffTime != TPLUS_ABNORMAL_DATETIME:
                return TPLUS_MACH_POWER_STATE_OFF
        return TPLUS_MACH_POWER_STATE_NONE
            
        
    def getPowerOnTime(self):
        return self.mPowerOnTime
    
    def getPowerOffTime(self):
        return self.mPowerOffTime
        
    def setPowerOnTime(self, PowerOnTime):
        self.mPowerOnTime = PowerOnTime
    
    def setPowerOffTime(self, PowerOffTime):
        self.mPowerOffTime = PowerOffTime
        
if __name__ == '__main__':
    d={'mPowerOffTime': None, 'mPowerOnTime': None, 'mMachID': 1, 'mMachName': u'xx'} 
    print MachModel(**d)       
    print dir(MachModel(**d))
    print d.keys() in dir(MachModel(**d))
    print d.keys()
    for key in d.keys():
        if key in dir(MachModel(**d)):
            print key,"in it"
        else:
            print key,"not in"
    
    print dir(MachModel())